package security;

import java.io.File;
import java.io.IOException;

/**
 * Abstract class for signature(digital signature algorithm)
 */
public abstract class Signature {

    /**
     *
     * @param file a file
     * @return signature of the file
     * @throws java.io.IOException  If an I/O error occurs
     */
    protected abstract byte [] signatureFile(File file)
            throws  IOException;

    /**
     *
     * @param file a file
     * @param init index from which the bytes will be read
     * @param offset number of bytes will be read
     * @return signature of the file
     * @throws java.io.IOException  If an I/O error occurs
     */
    protected abstract byte [] signatureFile(File file, long init, long offset)
            throws IOException;

    /**
     *
     * @param obj an object
     * @return signature of the object
     * @throws java.io.IOException  If an I/O error occurs
     */
    protected abstract byte [] signatureObject(Object obj)
            throws IOException;

    /**
     *
     * @param file a file
     * @return signature of the file
     * @throws java.io.IOException  If an I/O error occurs
     */
    public byte [] getSignature(File file)
            throws IOException{
		return signatureFile(file);	
	}
	
    /**
     *
     * Gets the signature of an file
     *
     * @param file a file
     * @param init index from which the bytes will be read
     * @param offset number of bytes will be read
     * @return signature of the file
     * @throws java.io.IOException  If an I/O error occurs
     */
    public byte [] getSignature(File file, long init, long offset)
            throws IOException{
		return signatureFile(file,init,offset);
	}

    /**
     * Gets the signature of an object
     *
     * @param obj an object
     * @return signature of the object
     * @throws java.io.IOException  If an I/O error occurs
     */
    public byte [] getSignature(Object obj)
            throws IOException{
		return signatureObject(obj);	
	}

}
